package com.sun.weekend.ui.activity;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.widget.Toast;

import com.sun.weekend.R;
import com.sun.weekend.base.BaseActivity;
import com.sun.weekend.base.Constants;
import com.sun.weekend.beans.BundleBean;

import java.lang.reflect.Method;

/**
 * @author sunleilei
 */

public class ModuleActivity extends BaseActivity{
    private Fragment fragment;
    private FragmentManager fragmentManager;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.module_activity);
        fragmentManager = getSupportFragmentManager();
        BundleBean bundleBean = (BundleBean) bundle.getSerializable(Constants.BUNDLE_BEAN);
        try {
            String moduleName = getPackageName()+".ui.fragment."+bundleBean.getSign()+"Fragment";
            Class clazz = Class.forName(moduleName);
            if (clazz == null) {
                Toast.makeText(this, "敬请期待!", Toast.LENGTH_SHORT).show();
            }else{
                try {
                    Method method = clazz.getMethod("newInstance");
                    fragment = (Fragment) method.invoke(null);
                    fragmentManager.beginTransaction().replace(R.id.fragment_container,fragment).commit();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
        }
    }
}
